package com.glaze.edu;

import com.glaze.edu.annotation.Autowired;
import com.glaze.edu.annotation.Component;
import com.glaze.edu.annotation.Service;
import com.glaze.edu.dao.AccountDao;
import com.glaze.edu.dao.impl.JdbcAccountDaoImpl;
import com.glaze.edu.factory.BeanFactory;
import com.glaze.edu.service.TransferService;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Field;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
 * @Description:
 * @auther ZhouLiGuo
 * @Date 2020/10/15 2:01 上午:57
 * @Version 1.0
 */
@Service("demo")
public class Demo {

    @Autowired
    public AccountDao accountDao;

    public static void main(String[] args) throws Exception {
        TransferService transferService = BeanFactory.getBean("transferService");
        System.out.println(transferService);
        transferService.transfer("6029621011000","6029621011001",100);
//        Class<?> aClass = Class.forName("com.glaze.edu.Demo");
//        Annotation[] annotations = aClass.getAnnotations();
//        System.out.println(annotations);


    }

    @Test
    public void test () throws Exception {
        Class<?> aClass = Class.forName("com.glaze.edu.Demo");
        Demo demo = (Demo) aClass.newInstance();
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            if(declaredField.isAnnotationPresent(Autowired.class)){
                declaredField.set(demo,Class.forName("com.glaze.edu.dao.impl.JdbcAccountDaoImpl").newInstance());
            }
        }
        System.out.println(demo.accountDao);
    }


}
